﻿using System;
using System.Collections.Specialized;

namespace VitCode.Castle.Helper
{
    /// <summary>
    /// DataValues 的摘要说明。
    /// </summary>
    public class DataColumnValues
    {
        private NameObjectDictionary rowValueCollection = new NameObjectDictionary();

        /// <summary>
        /// 
        /// </summary>
        public DataColumnValues()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="checkedValue"></param>
        /// <param name="columnIndex"></param>
        /// <returns></returns>
        public int GetRepeatRowNumber(string checkedValue, string columnIndex)
        {
            StringDictionary valueCollection = (StringDictionary) rowValueCollection[columnIndex];
            string rowNumber = valueCollection[checkedValue];
            if (rowNumber != null)
                return Convert.ToInt32(rowNumber);
            else
                return -1;

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="columnIndex"></param>
        /// <param name="checkedValue"></param>
        /// <param name="rowIndex"></param>
        /// <returns></returns>
        public bool Contains(string columnIndex, string checkedValue, int rowIndex)
        {
            StringDictionary hadReadValueCollection = (StringDictionary) rowValueCollection[columnIndex];

            string rowIndexStr = Convert.ToString(rowIndex);

            if (hadReadValueCollection == null)
            {
                hadReadValueCollection = new StringDictionary();
                hadReadValueCollection.Add(checkedValue, rowIndexStr);
                rowValueCollection.Add(columnIndex, hadReadValueCollection);
                return false;
            }
            else
            {
                if (hadReadValueCollection[checkedValue] != null)
                {
                    return true;
                }
                else
                {
                    hadReadValueCollection.Add(checkedValue, rowIndexStr);
                    rowValueCollection.Add(columnIndex, hadReadValueCollection);
                    return false;
                }
            }
        }

        /// <summary>
        /// 是否已经包含了这个数值
        /// </summary>
        /// <param name="columnIndex">列Index</param>
        /// <param name="checkedValue">列数值</param>
        /// <param name="rowIndex">行号</param>
        /// <returns></returns>
        public bool Contains(int columnIndex, string checkedValue, int rowIndex)
        {
            string StrColumnIndex = Convert.ToString(columnIndex);
            return Contains(StrColumnIndex, checkedValue, rowIndex);
        }
    }
}
